import { getShopCate, getShopList } from "@/static/js/pointsMall.js";
import { getUserInfo } from "@/static/js/my.js";
export default {
  data() {
    return {
      tabList: [],
      current: 0, //一级导航序号
      tabType: 0, //判断索引
      shopList: [], //商品列表
      userInfo: {}, //用户信息

      pageShow: false,
    };
  },
  onLoad() {
    this.getShopCate();
    this.getShopList();
  },
  onShow() {
    this.getUserInfo();
  },
  methods: {
    //获取用户信息
    getUserInfo() {
      getUserInfo().then((res) => {
        this.userInfo = res.data;
        this.pageShow = true;
      });
    },

    //获取商品分类
    async getShopCate() {
      let res = await getShopCate();
      if (res.code === 1) {
        this.tabList = res.data;
        this.tabList.unshift({
          name: "全部",
          id: 0,
        });
      } else {
        this.$tools.msg(res.msg);
      }
    },

    //获取商品列表
    async getShopList() {
      let obj = {
        cate_id: this.tabType,
      };
      let res = await getShopList(obj);
      if (res.code === 1) {
        this.shopList = res.data;
      } else {
        this.$tools.msg(res.msg);
      }
    },

    //选项点击事件
    tabClick(val) {
      this.tabType = val.id;
      this.getShopList();
    },

    //商品详情
    goShopDetail(val) {
      uni.navigateTo({
        url: "/pointsMall/shopDetail/index?id=" + val.id,
      });
    },

    //去兑换记录
    goShopRecord(e) {
      uni.navigateTo({
        url: `/pointsMall/pointsDetail/index?index=${e}`,
      });
    },
  },
};